<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;
class LoginController extends Controller
{
   public function index(){
    date('Y-m-d H:i:s',time());
    return view('admin/login/index');
   }
   public function Login(Request $request){

     $res = $request -> only(['username','power','password']);
  

     // 商家 
        if($res['power'] == 1){

              $data = DB::table('users')->where('username',$res['username'])->where('power',$res['power'])->first();
              $id = $data['id'];
              session(['username'=>$data['username']]);
           if(Hash::check($res['password'],$data['password'])){
            session(['id'=>$id]);

              return redirect('/admin/goods/index?id='.$id)->with('success','登录成功');
          }else{
              return back()->with('error','登录失败,用户名或密码有误');
          }
        }else{
             $data = DB::table('users')->where('username',$res['username'])->where('power',$res['power'])->first();
        if(Hash::check($res['password'],$data['password'])){
          session(['id'=>$data['id']]);
          session(['username'=>$data['username']]);
          session(['upic'=>$data['upic']]);
          
            return redirect('/admin/admin')->with('success','登录成功');
        }else{
            return back()->with('error','登录失败,用户名或密码有误');
        }
        }
      // 超级管理员 
       // 查询数据
     
     }

  
}
 
    
           

